﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using WX.WMS.DataModel;
using WX.WMS.Common;
using WX.WMS.BLL;

public partial class Product_PD_NQ_Select_Products_Window : PageBase
{
    private string _key
    {
        get
        {
            return Convert.ToString(ViewState["_key"]);
        }
        set
        {
            ViewState["_key"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            searchDand();
            Stock.DataSource = new StoreHouseBLL().GetStockList();
            Stock.DataBind();
            Area.DataSource = new StoreHouseBLL().GetStockAreaList();
            Area.DataBind();
            Floor.DataSource = new FloorBLL().GetFloorList();
            Floor.DataBind();
        }

    }
    protected void searchButton_Click(object sender, ImageClickEventArgs e)
    {
        //string strKey = "";
        //string strBarCode = "";
        //strKey = Key.Text.ToString();
        //strBarCode = barcode.Text.Trim();
        ////searchDand(strType, strBrand, strKey);
        //Response.Redirect(string.Format("CK_NQ_Select_Products_Window.aspx?action=search&Key={0}&BarCode={1}", strKey, strBarCode));

        searchDand();
    }

    protected void searchDand()
    {
        StoreBLL BllStore = new StoreBLL();
        // object key= Request.QueryString["Key"];
        object key = this.Key.Text.Trim();
        if (key != null && key != "")
        {
            BllStore.AddLikeCondition("T_PRODUCT.Name", key.ToString());
        }
        //object BarCode = Request.QueryString["BarCode"];
        object BarCode = this.barcode.Text.Trim();
        if (BarCode != null && BarCode != "")
        {
            BllStore.AddLikeCondition("T_PRODUCT_DETAIL.BAR_CODE", BarCode.ToString());
        }
        SearchResult.DataSource = BllStore.GetStoreList().ToList();
        SearchResult.DataBind();
    }


    protected void SearchResult_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (cbSelectAll.Checked)
        {
            StoreBLL BllStore = new StoreBLL();
            object key = this.Key.Text.Trim();
            if (key != null && key != "")
            {
                BllStore.AddLikeCondition("T_PRODUCT.Name", key.ToString());
            }
            object BarCode = this.barcode.Text.Trim();
            if (BarCode != null && BarCode != "")
            {
                BllStore.AddLikeCondition("T_PRODUCT_DETAIL.BAR_CODE", BarCode.ToString());
            }
            IList<T_STORE> sources = BllStore.GetStoreList().ToList();
            StringBuilder builder = new StringBuilder();
            foreach (T_STORE store in sources)
            {
                builder.Append(store.ID.ToString());
                builder.Append(",");
            }
            if (builder.Length == 0)
            {
                ShowMessage("请选择商品");
                return;
            }
            builder.Remove(builder.Length - 1, 1);

            Jscript.CloseWindowReturnValues(builder.ToString());
        }
        else
        {
            if (string.IsNullOrEmpty(this.SearchResult.GetKeyValues))
            {
                ShowMessage("请选择商品");
                return;
            }

            Jscript.CloseWindowReturnValues(this.SearchResult.GetKeyValues);
            return;
        }
    }
    protected void SearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.SearchResult.PageIndex = e.NewPageIndex;
        searchDand();
    }
}
